/**
 * Created by lwy on 2017/8/10.
 */

var userKey;
var pass;

$(function(){
    $.ajax({
        url:'/crm/shiroLongC/userLoginKey.json',
        dataType:'json',
        data:{
            userName:localStorage.getItem('crmphone'),
        },
        type:'post',
        success:function(data){
            if(data.code==1){
                userKey = data.datas.userKey;
            }
        }
    })
})

$('#save3').click(function(){
    if($('#editPass').val()==""){
        alert('密码不能为空');
    }
    if($('#editPass').val()!=$('#editconPass').val()){
        alert('两次输入的密码不一样');
        return;
    }
    pass= calcMD5($('#editPass').val() + userKey, 32);
    $.ajax({
        url:'/crm/userC/updateCRMPassword.json',
        dataType:'json',
        data:{
            token:localStorage.getItem('crmtoken'),
            password:pass,
        },
        type:'post',
        success:function(data){
            if(data.code==-1){
                window.parent.location.href="/crm/login.jsp"
            }
            if(data.code==0){
                alert(data.msg)
                return;
            }
            if(data.code==1){
                alert('修改成功');
                    localStorage.removeItem('crmtoken');
                    window.parent.location.href="/crm/login.jsp"
            }
        }
    })
})
